import request from '/utils/http.js';
import requestHandler from '@/utils/requestHandler';

export async function getAtms() {
	return await requestHandler(`/api/atm/getATM`, 'POST', {
		'Content-Type': 'application/json'
	}, {
		areaId: 66
	});
}

export async function getAtmById(atmId) {
	let result = await getAtms();
	let atm = null;
	if (result === undefined) {
		result = await getAtms();
	}
	if (result.data) {
		result.data.forEach(d => {
			if (d.id === +atmId) {
				atm = d;
			}
		});
	}
	return atm;
}

export async function getAtmByArea(areaId) {
	const result = await request({
		url: '/api/atm/getATM',
		method: 'POST',
		header: {
			'Content-Type': 'application/json'
		},
		data: {
			areaId
		}
	});

	return result;
}

export async function getAtmsByUserId(userId) {
	return await requestHandler('/api/user/getAtmList', 'GET', {}, {
		userId
	});
}